package com.example.watchfaceanimation;

import android.animation.ObjectAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.TextView;

import androidx.annotation.Nullable;

public class RunTextView extends androidx.appcompat.widget.AppCompatTextView {
    private static final String TAG = "RunTextView";

    public RunTextView(Context context) {
        super(context);
    }

    public RunTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public RunTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private int duration = 1500;
    private float number;

    public float getNumber() {
        Log.i(TAG, "getNumber: ");
        return -100F;
    }

    public void setNumber(float number) {
        Log.i(TAG, "setNumber: set number");
        this.number = number;
        setText(String.format("%,.2f", number));
    }

    /**
     * 显示
     *
     * @param number
     */
    public void runWithAnimation(float number) {
        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(
                this, "number", 0, number);
        objectAnimator.setDuration(duration);
        objectAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
        objectAnimator.start();
    }

}
